﻿using RoadQualityEvalAPI.Models;
using RoadQualityEvaluatorData.DomainServices.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RoadQualityEvalAPI.Controllers
{
    [Authorize(Roles="Admin")]
    public class HomeController : Controller
    {

        private TripStatsRepository _tripStatsRepo;

        [AllowAnonymous]
        public ActionResult Index()
        {
            return View();
        }


        public ActionResult Admin()
        {
            this._tripStatsRepo = new TripStatsRepository();

            var trips = new List<TripStatsModel>();

            if (_tripStatsRepo.GetAll().Count > 0)
            {
                foreach (var trip in _tripStatsRepo.GetAll())
                {
                    trips.Add(new TripStatsModel()
                    {
                        CreatedAt = trip.CreatedAt,
                        Info = trip.TripInfo,
                        TripAverageRoughness = trip.TripAverageRoughness,
                        TripAverageSpeed = trip.TripAverageSpeed,
                        TripDistance = trip.TripDistance,
                        TripNoOfSpeedbumps = trip.TripNoOfSpeedbumps,
                        TripNoOfPotholes = trip.TripNoOfPotholes,
                        TripDurationMillis = trip.TripDurationMillis
                    });
                }
            }

            return View("~/Views/Admin/Admin.cshtml", trips);
        }

    }
}
